2020-2021 Sunseeker Telemetry and Lighting System
gpio_ex2_inputCapture.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // Software Port Interrupt Service on P1.1 from LPM4 with
34 // Internal Pull-up Resistance Enabled
35 //
36 // A hi "TO" low transition on P1.1 will trigger P1_ISR which,
37 // toggles P1.0. P1.1 is internally enabled to pull-up. Normal mode is
38 // LPM4 ~ 0.1uA. LPM4 current can be measured with the LED removed, all
39 // unused Px.x configured as output or inputs pulled high or low. On the
40 // MSP430FR5969 LaunchPad, P1.1 is connected to button S1. The interrupt is
41 // triggered once the switch is released.
42 // ACLK = n/a, MCLK = SMCLK = default DCO
43 //
44 // Tested On: MSP430FR5969
45 // -----------------
46 // /|\| XIN|-
47 // | | |
48 // --|RST XOUT|-
49 // /|\ | |
50 // --o--|P1.1 P1.0|-->LED
51 // \|/
52 //
53 // This example uses the following peripherals and I/O signals. You must
54 // review these and change as needed for your own board:
55 // - GPIO Port peripheral
56 //
57 // This example uses the following interrupt handlers. To use this example
58 // in your own application you must add these interrupt handlers to your
59 // vector table.
60 // - PORT1_VECTOR
61 //******************************************************************************
62 #include "driverlib.h"
63 
64 void main (void)
65 {
66  //Stop watchdog timer
67  WDT_A_hold(WDT_A_BASE);
68 
69  //Set P1.0 to output direction
70  GPIO_setAsOutputPin(
71  GPIO_PORT_P1,
72  GPIO_PIN0
73  );
74 
75  //Enable P1.1 internal resistance as pull-Up resistance
76  GPIO_setAsInputPinWithPullUpResistor(
77  GPIO_PORT_P1,
78  GPIO_PIN1
79  );
80 
81  //P1.1 Hi/Lo edge
82  GPIO_selectInterruptEdge(
83  GPIO_PORT_P1,
84  GPIO_PIN1,
85  GPIO_HIGH_TO_LOW_TRANSITION
86  );
87 
88  /*
89  * Disable the GPIO power-on default high-impedance mode to activate
90  * previously configured port settings
91  */
92  PMM_unlockLPM5();
93 
94  //P1.1 IFG cleared
95  GPIO_clearInterrupt(
96  GPIO_PORT_P1,
97  GPIO_PIN1
98  );
99 
100  //P1.1 interrupt enabled
101  GPIO_enableInterrupt(
102  GPIO_PORT_P1,
103  GPIO_PIN1
104  );
105 
106  //Enter LPM4 w/interrupt
107  __bis_SR_register(LPM4_bits + GIE);
108 
109  //For debugger
110  __no_operation();
111 }
112 
113 //******************************************************************************
114 //
115 //This is the PORT1_VECTOR interrupt vector service routine
116 //
117 //******************************************************************************
118 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
119 #pragma vector=PORT1_VECTOR
120 __interrupt
121 #elif defined(__GNUC__)
122 __attribute__((interrupt(PORT1_VECTOR)))
123 #endif
124 void Port_1 (void)
125 {
126  //P1.0 = toggle
127  GPIO_toggleOutputOnPin(
128  GPIO_PORT_P1,
129  GPIO_PIN0
130  );
131 
132 
133  //P1.1 IFG cleared
134  GPIO_clearInterrupt(
135  GPIO_PORT_P1,
136  GPIO_PIN1
137  );
138 }
139 
void Port_1(void)
void main(void)
__no_operation()